public class MyCircularQueue {
        private int[] elem;
        private int front;
        private int rear;
        public MyCircularQueue(int k){ //构造器，设置队列长度为k
            this.elem = new int[k];
        }
        public boolean enQueue(int value){ //向循环队列插入元素，若成功则返回true
            if(isFull()){
                return false;
            }
            elem[rear] = value;
            rear = (rear+1)%elem.length;
            return true;
        }
        public boolean deQueue(){//从循环队列中删除一个元素，若成功返回true
            if (isFull()){
                return false;
            }else {
                front = (rear+1)% elem.length;
                return true;
            }
        }
        public int Front(){ //从队首获取元素，若队列为空返回-1
            if (isEmpty()){
                return -1;
            }
            return elem[front];
        }
        public int Rear(){//从队尾获取元素，若队列为空返回-1
            if (isEmpty()){
                return -1;
            }
            int index = (rear == 0) ? elem.length-1 : rear-1;
            return elem[index];
        }
        public boolean isEmpty(){
            return front == rear;
        }
        public boolean isFull(){
            if ((rear+1)% elem.length == front){
                return true;
        }
            return false;
    }
}
